<?php

require_once('includes/config.php');
include('includes/sc-includes.php');

$query_contacts = "SELECT * FROM contacts";
$row_contacts = $sdb->select('contacts', $query_contacts);
$totalRows_contacts = count($row_contacts);

$csv_output = '"id","First Name","Last Name","Title","Company","Street","City","State","Zip","Email","Phone","Fax","Website","Profile"';
$csv_output .= "\n";

$i = 0;

while ($i < $totalRows_contacts)
{
    $csv_output .= '"'.$row_contacts[$i]['Attributes']['contact_id'].'","'.$row_contacts[$i]['Attributes']['contact_first'].'","'.$row_contacts[$i]['Attributes']['contact_last'].'","'.$row_contacts[$i]['Attributes']['contact_title'].'","'.$row_contacts[$i]['Attributes'][$i]['Attributes']['contact_company'].'","'.$row_contacts[$i]['Attributes']['contact_street'].'","'.$row_contacts[$i]['Attributes']['contact_city'].'","'.$row_contacts[$i]['Attributes']['contact_state'].'","'.$row_contacts[$i]['Attributes']['contact_zip'].'","'.$row_contacts[$i]['Attributes']['contact_email'].'","'.$row_contacts[$i]['Attributes']['contact_phone'].'","'.$row_contacts[$i]['Attributes']['contact_fax'].'","'.$row_contacts[$i]['Attributes']['contact_web'].'","'.$row_contacts[$i]['Attributes']['contact_profile'].'"';
	$csv_output .= "\n";
	$i++;
}

  //You cannot have the breaks in the same feed as the content.
  header("Content-type: application/vnd.ms-excel");
  header("Content-disposition: csv; filename=simplecustomer.csv");
  print $csv_output;
  exit;
?>

